package com.pda.gongpin.presenter;

import com.pda.gongpin.bean.ScanResultBean;
import com.pda.gongpin.bean.StorageBinIdBean;
import com.pda.gongpin.bean.request.EmptyShipmentsRequest;
import com.pda.gongpin.bean.request.QRcodeRequest;
import com.pda.gongpin.bean.request.RecommendRequest;
import com.pda.gongpin.contract.EmptyPalletOutContract;
import com.pda.gongpin.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class EmptyPalletOutPresenter extends BasePresenter<EmptyPalletOutContract .View> implements EmptyPalletOutContract.Presenter {
    @Override
    public void scanTheQRCodeToVerify(QRcodeRequest request) {
        NetUtils.geApi().scanTheQRCodeToVerify(request)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ScanResultBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ScanResultBean> stringBaseAppEntity) throws Exception {
                        getView().setScan(stringBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void emptyshipments(EmptyShipmentsRequest body) {
        NetUtils.geApi().emptyshipments(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<StorageBinIdBean>>() {
                    @Override
                    public void accept(BaseAppEntity<StorageBinIdBean> stringBaseAppEntity) throws Exception {
                        getView().showMessage(stringBaseAppEntity.getMsg());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void recommend(RecommendRequest body) {
        NetUtils.geApi().recommend(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<StorageBinIdBean>>() {
                    @Override
                    public void accept(BaseAppEntity<StorageBinIdBean> stringBaseAppEntity) throws Exception {
                        getView().setRecommend(stringBaseAppEntity.getData().getStorageBinId());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
